<?
include('../scaffold/tag.php');
include('../controller/handler.php');
include('../controller/philomousia.php');

include('../module/var.inc.php');

session_start();

$hd = new Handler();
$base_url = $hd->getBaseURL();

if(isset($_POST['sent_login'])) {
	$failed = false;
	if($hd->getUsername()==$_POST['username'] && $hd->getPassword()==sha1($_POST['password'])) {
		$_SESSION['password'] = $_POST['password'];
		$hd->writeLog("[LOGIN] ".strftime("%c")." ".$_POST['username']." logged in ".
			"ID=".$_SERVER['REMOTE_ADDR']);
	} else {
		$failed = true;
		$hd->writeLog("[LOGIN] ".strftime("%c")." failed with ".$_POST['username']."-".$_POST['password'].
			" ID=".$_SERVER['REMOTE_ADDR']);
	}
}
if(isset($_POST['sent_logout'])) {
	$hd->writeLog("[LOGIN] ".strftime("%c")." ".$hd->getUsername()." logged out".
		" ID=".$_SERVER['REMOTE_ADDR']);
	session_unset();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
	<? include('../module/head.inc.php'); ?>
	<meta name="robots" content="noindex, nofollow"/>
	<script src="<?echo $base_url;?>js/editor.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="content">
<?include('../module/header.inc.php');?>

<?if($hd->getPassword()!=sha1($_SESSION['password'])) {?>
<div id="login">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
	<form action="panel" method="post" accept-charset="utf-8" id="login_form" class="form  <?if($failed) echo 'login_error'; ?>" onsubmit="return loginForm(this);;">
	<h2>Login</h2>
	<input type="text" class="text" name="username" value="<?echo $_POST['username'];?>" /> Username<br />
	<input type="password" class="text" name="password" value="<?echo $_POST['password'];?>" /> Password<br />
	<input type="hidden" name="sent_login" value="true" />
	<p><input type="submit" value="Login &rarr;"></p>
	<p class="small"><a href="<?echo $base_url;?>recover">Password dimenticata?</a></p>
	</form>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>	
<?} else {
	//ADMIN LOGGED
	$info = 'onmouseover="showInfo(this)" onmouseout="hideInfo(this)"';
?>
<div id="admin"></div>

<div class="form">
<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
<div class="body_main_left">
<div class="body_main_right">
<div class="body_main">

<div id="logout">
	<form action="panel" method="post" accept-charset="utf-8" id="logout_form">
	<input type="hidden" name="sent_logout" value="true" />
	<input type="submit" value="Logout &rarr;">
	</form>
	Benvenuto nel pannello di amministrazione di &Phi;lomousia.
</div>
<table id="panel_chooser" border="0" cellspacing="10" cellpadding="0">
	<tr>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/editorial">Aggiorna editoriale</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/tag">Gestisci argomenti</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/preferences">Modifica preferenze</a></div></td>
	</tr>
	<tr>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/article">Aggiungi articolo</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/file">Carica file</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/password">Cambia Password</a></div></td>
	</tr>
	<tr>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/person">Aggiungi persona</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/file/delete">Elimina file</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/banner">Banner</a></div></td>
	</tr>
	<tr>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/link">Aggiungi link</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="<?echo $base_url?>panel/reset">Reset dati</a></div></td>
		<td><div class="panel_button"><a <?echo $info;?> href="http://www.google.com/analytics/it-IT/" target="_blank">Statistiche</a></div></td>
	</tr>
</table>
</div></div></div>
<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>

<div class="article">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
		<h2>Log di sistema</h2>
		<p>Traccia di tutte le operazioni effettuate in &Phi;lomousia. 
		<span class="pseudo_link" onclick="new Effect.toggle('log', 'blind')">Mostra/nascondi</span> </p>
		<div id="log" style="display:none">
			<div id="log_entry" class="tiny">
			<ol>
			<?
			$script = 'onmouseover="selectLogEntry(this);" onmouseout="normalizeLogEntry(this)"';
			$entries = explode("\n", $hd->getLog());
			$total = count($entries);
			for($i=0; $i<$hd->getLogLines() && $i<$total; $i++) {
				echo "<li ".$script.">".$entries[$total-$i-1]."</li>";
			}
			?>
			</ol>
			</div>
		</div>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>

<?}?>

<? include('../module/footer.inc.php'); ?>
</div>
</body>
</html>
